package com.usian.rabbitmqdemo.listener;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.util.Date;

@Component
@RabbitListener(queues = "cjqueue")
public class CJListener {


    /***
     * 监听消息
     * @param msg
     */
    @RabbitHandler
    public void listenDelayedQueue(@Payload Object msg) throws UnsupportedEncodingException {
        Message message = (Message) msg;
        String str =  new String(message.getBody(),"utf-8");
        System.out.println("接收到 delay.queue的延迟消息：{}"+ str+"时间"+new Date());
    }

}
